<template>
	<!-- 页面内容--身份证拍照、活体检测 页面 -->
	<view style="width: 100vw; min-height: 100vh;background-color: #1F2022; color: #fff;">
		<formheadVue :headname="$t('idcard.idcard')" :pagenum='3'></formheadVue>
		<view class="P-head">
			<view class="P-1 flexcentercloumn">
				<image src="../../static/stepthree.png" mode=""></image>
				<p>สินเชื่อ</p>
				<p>"หมายเลข"</p>
			</view>
			<view class="P-2" style="margin-top: 20px;">
				<view class="P-2-title flexrowstart">
					<image src="../../static/idcardicon.png" mode=""></image>
					<text class="gradient-text">{{$t('idcard.idcard')}}</text>
				</view>
			</view>
			<view class="P-idimg-box flexcentercloumn">
				<image :style="{
					  padding: !idacrdPasses && handleClick ? '40rpx' : '',
					  background: !idacrdPasses && handleClick ? 'rgba(255, 245, 132, 0.8)' : '',
					  borderRadius: !idacrdPasses && handleClick ? '30rpx' : ''
					}" :src="idcardsrc" @click="openIdcardCamera()"></image>
			</view>
			<view class="P-id flexrowspacebetween">
				<image src="../../static/idcard1.png" mode=""></image>
				<image src="../../static/idcard2.png" mode=""></image>
				<image src="../../static/idcard3.png" mode=""></image>
				<image src="../../static/idcard4.png" mode=""></image>
			</view>
			<view style="margin-top: 20px;">
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.englishName')}}</text>
				</view>
				<view class="P-5" :style="getBorderStyle(englishName)">
					<uni-easyinput style="height: 100%;" :styles="from.styles" :placeholderStyle="from.placeholderStyle"
						:placeholder="$t('pleaseinput')" v-model="englishName" @blur="endTiming('englishName')"
						@focus="startTiming('englishName')"></uni-easyinput>
				</view>
			</view>
			<view>
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.thaiName')}}</text>
				</view>
				<view class="P-5" :style="getBorderStyle(idcrdThaiName)">
					<uni-easyinput style="height: 100%;" :styles="from.styles" :placeholderStyle="from.placeholderStyle"
						:placeholder="$t('pleaseinput')" v-model="idcrdThaiName" @blur="endTiming('idcrdThaiName')"
						@focus="startTiming('idcrdThaiName')"></uni-easyinput>
				</view>
			</view>
			<view>
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.aliasName')}}</text>
				</view>
				<view class="P-5" :style="getBorderStyle(otherThaiName)">
					<uni-easyinput style="height: 100%;" :styles="from.styles" :placeholderStyle="from.placeholderStyle"
						:placeholder="$t('pleaseinput')" v-model="otherThaiName" @blur="endTiming('otherThaiName')"
						@focus="startTiming('otherThaiName')"></uni-easyinput>
				</view>
			</view>
			<view>
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.gender')}}</text>
				</view>
				<view class="P-5" style="padding: 0rpx;" @click="clickeFun('gendercode')">
					<uni-data-select :emptyTips="$t('emptyTips')" style="height: 100%;width: 100%;padding: 6rpx 20rpx;
					box-sizing: border-box;" :style="getBorderStyle(gendercode)" :placeholder="$t('pleaseselect')"
						v-model="gendercode" @change="handleSelectChange('gendercode')" :localdata="dropdowns.sex">
					</uni-data-select>
				</view>
			</view>
			<!--  时间 -->
			<view @click="clickeFun('birthValue')">
				<view style="margin-bottom: 10px;margin-top: 10px;" @click="showdatePciker = true">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.birthday')}} (MM/DD/YY)</text>
					<u-datetime-picker :key="birthPickerKey" ref="datetimePicker" :show="showdatePciker"
						:minDate="-2208988800000" v-model="birthValue" @confirm="datePcikerConfirm"
						:confirmText="$t('index.confirm')" :cancelText="$t('index.cancel')" @cancel="datePcikerCancel"
						mode="date" :formatter="formatter" @change="handleSelectChange('birthValue')">
					</u-datetime-picker>
					<!-- 	<view class="datapickerxiala"
						v-if='formatTimestamp(birthValue)!=formatTimestamp(Number(new Date()))'>
						{{formatTimestamp(birthValue)}}
						<u-icon
						style="position: absolute;
						right: 30rpx;
						bottom: 40rpx;
						"
						 name="arrow-down" color="#FFF584" size="14"></u-icon>
					</view>
					<view v-else class="datapickerxiala" :style="{
							border: this.handleClick? '6rpx solid #FFF584' : '',
							borderRadius: this.handleClick? '40rpx':'',
						}">
						<u-icon
						style="position: absolute;
						right: 30rpx;
						bottom: 40rpx;
						"
						 name="arrow-down" color="#FFF584" size="14"></u-icon>
						<span style="color:#999;">{{$t('pleaseselect')}}</span>
					</view> -->
					<view class="datapickerxiala"
						v-if='(formatTimestamp(birthValue)!=formatTimestamp(Number(new Date())) || showtoadybirth)'>
						{{formatTimestamp(birthValue)}}
						<u-icon style="position: absolute;
						right: 30rpx;
						bottom: 40rpx;
						" name="arrow-down" color="#FFF584" size="14"></u-icon>
					</view>
					<view v-else class="datapickerxiala" :style="{
							border: this.handleClick? '6rpx solid #FFF584' : '',
							borderRadius: this.handleClick? '40rpx':'',
						}">
						<u-icon style="position: absolute;
						right: 30rpx;
						bottom: 40rpx;
						" name="arrow-down" color="#FFF584" size="14"></u-icon>
						<span style="color:#999;">{{$t('pleaseselect')}}</span>
					</view>
				</view>
			</view>
			<!-- 身份证 -->
			<view>
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.idcardNum')}}</text>
				</view>
				<view class="P-5" :style="getBorderStyle(idnumber)">
					<uni-easyinput style="height: 100%;" :styles="from.styles" :placeholderStyle="from.placeholderStyle"
						:placeholder="$t('pleaseinput')" v-model="idnumber" maxlength="13" type="number"
						@blur="endTiming('idnumber')" @focus="startTiming('idnumber')"></uni-easyinput>
				</view>
			</view>
			<!-- 地址 -->
			<view>
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.address')}}</text>
				</view>
				<view class="P-5" :style="getBorderStyle(addressValue)">
					<uni-easyinput style="height: 100%;" :styles="from.styles" maxlength="50"
						:placeholderStyle="from.placeholderStyle" :placeholder="$t('pleaseinput')"
						v-model="addressValue" @blur="endTiming('addressValue')"
						@focus="startTiming('addressValue')"></uni-easyinput>
				</view>
			</view>
			<view class="P-2" style="margin-top: 20px;">
				<view class="P-2-title flexrowstart">
					<image src="../../static/idcardicon.png" mode=""></image>
					<text class="gradient-text">{{$t('idcard.faceecheck')}}</text>
				</view>
			</view>
			<!-- 活体检测内容 -->
			<!-- 		<view class="P-idimg-box flexcentercloumn">
				<image class="img" v-if="FaceCheckCount>2" :style="{
			  padding: !FacePasses && handleClick ? '40rpx' : '',
			  background: !FacePasses && handleClick ? 'rgba(255, 245, 132, 0.8)' : '',
			  borderRadius: !FacePasses && handleClick ? '30rpx' : ''
			}" :src="facesrc" @click="UploadFaceFile">
				</image>
				<image  class="img" v-else :style="{
								  padding: !FacePasses && handleClick ? '40rpx' : '',
								  background: !FacePasses && handleClick ? 'rgba(255, 245, 132, 0.8)' : '',
								  borderRadius: !FacePasses && handleClick ? '30rpx' : ''
								}" :src="facesrc" @click="FaceCheck">
				</image>
			</view> -->
			<view class="P-idimg-box flexcentercloumn">
				<image class="img" :style="{
			  padding: !FacePasses && handleClick ? '40rpx' : '',
			  background: !FacePasses && handleClick ? 'rgba(255, 245, 132, 0.8)' : '',
			  borderRadius: !FacePasses && handleClick ? '30rpx' : ''
			}" :src="facesrc" @click="UploadFaceFile">
				</image>
			</view>
			<view class="P-id flexrowspacebetween">
				<image class='facetipasimg' src="../../static/face1.png" mode=""></image>
				<image class='facetipasimg' src="../../static/face2.png" mode=""></image>
				<image class='facetipasimg' src="../../static/face3.png" mode=""></image>
			</view>
			<view style="margin-top: 40rpx;">
				<view style="margin-bottom: 10px;margin-top: 10px;">
					<text style="font-size: 18px;font-weight: 500">{{$t('idcard.loanrange')}}</text>
				</view>
				<view class="P-5 flexrowstart" style="color: #fff;">
					<p>{{$t('idcard.loanrangecontent')}}</p>
				</view>
			</view>
			<view class="P-6">
				<view class="content-1 flexcenter">
					<image src="../../static/worning.png" mode=""></image>
					<p>
						{{$t('gamilmsg')}}
					</p>
				</view>
			</view>
			<view style="margin-top: 30rpx;">
				<view @click="fn1()" class="P-2 flexcenter">
					<p> {{$t('continue')}}</p>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import formheadVue from '../../components/formhead.vue';
	import setDot from '@/pages/utils/setdot.js';
	import {
		requestAndroidPermission
	} from '../../js_sdk/wa-permission/permission.js'
	import api from '@/pages/utils/api.js'
	import setfengkongDot from '@/pages/utils/fengkong.js';
	import getDroupMeunFun from '@/pages/utils/getDroupMeun.js'
	export default {
		data() {
			return {
				showdatePciker: false,
				from: {
					placeholderStyle: "color:##FFF584;font-size:15px;",
					styles: {
						color: '##FFF584',
						borderColor: '#2979FF',
					},
				},
				dropdowns: {
					sex: [], //性别下拉菜单
				},
				idacrdPasses: false, //默认没上传
				idcrdThaiName: '',
				englishName: '',
				otherThaiName: '',
				gendercode: '',
				birthValue: Number(new Date()),
				idnumber: '',
				addressValue: '',

				handleClick: false, //默认没点击
				idcardsrc: '../../static/idkacrdfront.png',
				facesrc: '../../static/facebg.png',
				birthPickerKey: 0,
				currentlang: 'th',
				// 后半部分
				FacePasses: false, //默认没上传
				startTimes: {}, // 记录每个输入框的开始时间
				fillTimes: { // 存储填写时长
					idcardfrontupload: 0,
					faceupload: 0,
					englishName: 0,
					idcrdThaiName: 0,
					otherThaiName: 0,
					gendercode: 0,
					birthValue: 0,
					idnumber: 0,
					addressValue: 0,
					page: 0
				},
				faceFun: null,
				// FaceCheckCount: 0,
				facesocre: '99',
				showtoadybirth: false,
			};
		},
		components: {
			formheadVue
		},
		onLoad() {},
		onShow() {
			console.log('进入了onshow');
			if (this.idcardsrc == "../../static/idkacrdfrontes.png" || this.idcardsrc == "../../static/idkacrdfront.png") {
				let currentlang = uni.getLocale()
				if (currentlang == 'es') {
					console.log('currentlang！！！！', currentlang);
					this.idcardsrc = '../../static/idkacrdfrontes.png'
				} else {
					this.idcardsrc = '../../static/idkacrdfront.png'
				}
			} else {
				console.log('该页面上传过身份证', this.src);
			}
			this.showtoadybirth = uni.getStorageSync('setbirth') ? true : false
			console.log('点击过今天的日期了吗', this.showtoadybirth);
			this.currentlang = uni.getLocale()
			this.startTiming('page')
			//重新计算下拉框的填写时长
			this.clearSelectStartFlags()
			// this.getInfo()
			this.loadDropdownData();
			// this.faceFun = uni.requireNativePlugin('sn-faceliveness');
			// console.log('人脸插件', this.faceFun);
			// if (uni.getStorageSync('shouldUpload')) {
			// 	this.faceFun.setResultCallback((res) => {
			// 		console.log('需要拿活体检测结果', res);
			// 		const data = res.data;
			// 		if (res.type == 'finish') {
			// 			this.parseFun(data.actionList, data.videosBase64);
			// 			uni.removeStorageSync('shouldUpload')
			// 		}
			// 	});
			// }
		},
		computed: {
			getBorderStyle() {
				return (value) => {
					return this.checkempty(value) ? {
						border: '6rpx solid #FDF57C',
						borderRadius: '40rpx',
						width: '100%'
					} : {};
				};
			},
		},
		created() {

		},
		watch: {
			englishName(newVal) {
				// 只保留英文字母、空格和.
				let validValue = newVal.replace(/[^A-Za-z .]/g, '');

				if (/^[.\s]*$/.test(validValue)) {
					validValue = '';
				}
				if (validValue !== this.englishName) {
					this.$nextTick(() => {
						this.englishName = validValue;
					});
				}
			},
			idcrdThaiName(newVal) {
				let validValue = newVal.replace(/[^ก-๙\s]/g, '');
				if (/^\s*$/.test(validValue)) {
					validValue = '';
				}
				if (validValue !== this.idcrdThaiName) {
					this.$nextTick(() => {
						this.idcrdThaiName = validValue;
					})
				}
			},
			otherThaiName(newVal) {
				let validValue = newVal.replace(/[^ก-๙\s]/g, '');
				if (/^\s*$/.test(validValue)) {
					validValue = '';
				}
				if (validValue !== this.otherThaiName) {
					this.$nextTick(() => {
						this.otherThaiName = validValue;
					})
				}
			}
		},
		methods: {
			// FaceCheck() {

			// 	//记得修改 先看看有无相机权限
			// 	this.startTiming('upload')
			// 	console.log('走活体检测');
			// 	this.FaceCheckCount++
			// 	console.log('第几次', this.FaceCheckCount);
			// 	this.faceFun.requestCameraPermission((e) => {
			// 		console.log('执行了活体方法', e);
			// 		if (e.code == 0) {
			// 			this.faceFun.openFace({
			// 				videoTime: 2000,
			// 				isEnglish: false,
			// 				shuffle: true,
			// 				actionList: [0]
			// 			});
			// 			//刚上传成功需要在onload刷新页面上传给后台，否则直接回回显，无需上传
			// 			uni.setStorageSync('shouldUpload', true)
			// 		} else {
			// 			console.log('requestCameraPermission fail', e);
			// 		}
			// 	});
			// },
			UploadFaceFile() {
				console.log('走拍照');
				this.startTiming('faceupload')
				uni.chooseImage({
					sizeType: ['compressed '],
					count: 1,
					sourceType: ['camera'],
					success: (res) => {
						uni.showLoading({
							title: this.$t('uploading')
						})
						//上传方法调用
						this.pubilcUploadFun(res.tempFilePaths[0], '拍照')
					},
					fail: (err) => {
						requestAndroidPermission('android.permission.CAMERA')
					}
				});
			},
			pubilcUploadFun(filepathValue, channelName) {
				uni.uploadFile({
					// url: 'https://test.flashkaching.com/NeoLoan/aegf/dmcc',
					url: 'https://api.neoloanth.com/NeoLoan/aegf/dmcc',
					filePath: filepathValue,
					// file: res.tempFiles[0],
					name: 'frontImage',
					formData: {
						'vkbp': "120",
						"blhs": '02', //人脸，
						'nxbd': uni.getStorageSync('token') || '', //token
						"blxe": '100',
						"ignf": '1.0.0',
						"nkif": '',
						"jvjj": uni.getStorageSync('userId'),
						"afvk": this.facesocre,
					},
					header: {
						'nxbd': uni.getStorageSync(
							'token') || '', //token
						"client-id": '120',
						"blxe": '100',
						"ignf": '1.0.0',
						"nkif": '',
						"jvjj": uni.getStorageSync(
							'userId'),
						"mulFlag": 1,
						"vkpb": "120"
					},
					success: (uploadFileRes) => {
						this.endTiming('faceupload')
						console.log('人脸拍摄时长', this.fillTimes.faceupload);
						setfengkongDot('FacialRecognitionCompleteDuration', this.fillTimes.faceupload)
						if (channelName == '拍照') {
							console.log('拍照上传结果', uploadFileRes);
						} else {
							console.log('活体上传结果', uploadFileRes);
						}

						if (uploadFileRes.statusCode == 200) {
							let params = {
								vjeu: '4'
							}
							api.getPhotoUrl(params).then(data => {
								console.log('--人脸照片回显res', data);
								this.$nextTick(() => {
									this.facesrc = ''; // 先清空
									console.log('更新页面', data.bjid);
									this.facesrc = data.bjid;
								});
								this.FacePasses = true
								console.log('this.facesrc', this.facesrc);
								if (this.idacrdPasses && this.FacePasses) {
									api.ComparisonFaceIDcard().then(data => {
										console.log('认证对比分数！');
									})
								}
							})
							setDot('SYSTEM_FACE_SUCCESS')
						}
						uni.setStorageSync('facePhotoUpload', true)
						uni.hideLoading()
					},
					fail: (res) => {
						this.FacePasses = false
						console.log('上传失败', res);
						uni.showToast({
							icon: 'none',
							title: this.$t('idcard.errormsg')
						})
						uni.hideLoading()
					}
				});
			},
			async loadDropdownData() {
				try {
					const types = ["sex"];
					const promises = types?.map(type => getDroupMeunFun(type));

					const results = await Promise.all(promises);
					types.forEach((type, index) => {
						this.dropdowns[type] = results[index]?.map(item => ({
							value: item.ggbb,
							text: item.cjfu
						})) || [];
					});
					// this.getformData()
				} catch (error) {
					console.error("获取下拉数据失败", error);
				}
			},
			getformData() {
				let params = {
					vjeu: '4'
				}
				console.log('this.birthValue', this.birthValue);
				api.getUserInfo(params).then(data => {
					console.log('表格数据回显', data);
					// birthValue: Number(new Date()),
					this.idcrdThaiName = data.mcgw || ''
					this.englishName = data.scyd || ''
					this.otherThaiName = data.fspg || ''
					this.gendercode = data.iqlo || ''
					this.addressValue = data.gjoi || ''
					this.idnumber = data.tjhc || ''
					if (data.vzbc) {
						this.birthValue = Number(this.showData(data.vzbc)) || Number(new Date())
					}
					this.birthPickerKey++; // 触发组件重新渲染
					console.log('this.birthValue--》》', this.birthValue);
				})
			},
			showData(value) {
				console.log('value---》》', value);
				const [day, month, year] = value.split('-');
				const date = new Date(year, month - 1, day);
				const timestamp = date.getTime();
				return timestamp
			},
			formatTimestamp(timestamp) {
				const date = new Date(timestamp);
				const day = String(date.getDate()).padStart(2, '0');
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const year = date.getFullYear();
				return `${month}/${day}/${year}`;
			},
			parseDateToTimestamp(dateStr) {
				// 后台返回的格式是 "20 Dec. 1996"，先去掉句点
				const cleanStr = dateStr.replace(/\./g, ''); // "20 Dec 1996"
				const [day, monthStr, year] = cleanStr.split(' ');

				const monthMap = {
					Jan: 0,
					Feb: 1,
					Mar: 2,
					Apr: 3,
					May: 4,
					Jun: 5,
					Jul: 6,
					Aug: 7,
					Sep: 8,
					Oct: 9,
					Nov: 10,
					Dec: 11
				};

				const month = monthMap[monthStr];
				if (month === undefined) return NaN;

				const date = new Date(parseInt(year), month, parseInt(day));
				console.log('处理好的data', date.getTime())
				return date.getTime();
			},

			formatter(type, value) {
				if (type === 'year') {
					if (this.currentlang == 'es') {
						return `${value}año`
					} else {
						return `${value}ปี`
					}

				}
				if (type === 'month') {
					if (this.currentlang == 'es') {
						return `${value}luna`
					} else {
						return `${value}ดวงจันทร์`
					}
				}
				if (type === 'day') {

					if (this.currentlang == 'es') {
						return `${value}día`
					} else {
						return `${value}วัน`
					}
				}
				return value
			},
			checkempty(name) {
				// console.log('name-->', name);
				if (name == '' && this.handleClick) {
					// console.log('显示框');
					return true
				} else {
					// console.log('不显示框');
					return false
				}
			},
			datePcikerConfirm(e) {
				console.log('e', e);
				uni.setStorageSync('setbirth', true)
				this.showtoadybirth = uni.getStorageSync('setbirth') ? true : false
				this.birthValue = e.value
				this.showdatePciker = false
			},
			datePcikerCancel() {
				this.showdatePciker = false
			},
			getInfo() {
				let params = {
					vjeu: '4'
				}
				api.getPhotoUrl(params).then(data => {
					console.log('身份证人脸照片回显res-->>', data);
					if (data.fumf) {
						this.idcardsrc = data.fumf
						this.idacrdPasses = true
					}
					if (data.bjid) {
						this.facesrc = data.bjid
						this.FacePasses = true
					}
					// 从身份证埋点和封控埋点开始写
				})
			},
			getCurrentTimestamp() {
				return Date.now();
			},
			openIdcardCamera() {
				setDot('CLICK_ID_PICTURE_F_SUBMIT')
				console.log('走拍照');
				this.startTiming('idcardfrontupload')
				uni.chooseImage({
					sizeType: ['compressed '],
					count: 1,
					sourceType: ['camera'],
					success: (res) => {
						uni.showLoading({
							title: this.$t('uploading')
						})
						//上传方法调用
						this.idcardUploadFun(res.tempFilePaths[0])
					},
					fail: (err) => {
						requestAndroidPermission('android.permission.CAMERA')
					}
				});
			},
			idcardUploadFun(filepathValue) {
				uni.uploadFile({
					// url: 'https://test.flashkaching.com/NeoLoan/aegf/dmcc',
					url: 'https://api.neoloanth.com/NeoLoan/aegf/dmcc',
					filePath: filepathValue,
					name: 'frontImage',
					formData: {
						'vkbp': "120",
						"blhs": '00', //id卡，
						'nxbd': uni.getStorageSync('token') || '', //token
						"blxe": '100',
						"ignf": '1.0.0',
						"nkif": '',
						"jvjj": uni.getStorageSync('userId'),
						"afvk": '99',
					},
					header: {
						'nxbd': uni.getStorageSync(
							'token') || '', //token
						"client-id": '120',
						"blxe": '100',
						"ignf": '1.0.0',
						"nkif": '',
						"jvjj": uni.getStorageSync(
							'userId'),
						"mulFlag": 1,
						"vkpb": "120"
					},
					success: (uploadFileRes) => {
						this.endTiming('idcardfrontupload')
						console.log('身份证正面拍摄时长', this.fillTimes.idcardfrontupload);
						setfengkongDot('FrontCompleteDuration', this.fillTimes.idcardfrontupload)
						if (uploadFileRes.statusCode == 200) {
							console.log('对象格式', JSON.parse(uploadFileRes.data));
							const idcardData = JSON.parse(uploadFileRes.data)
							console.log('身份证拍照回显的信息', idcardData);
							if (idcardData.ggbb == 1000) {
								if (idcardData.simh.civn) {
									this.$nextTick(() => {
										this.englishName = idcardData.simh.civn.tgax || ''
										this.idcrdThaiName = idcardData.simh.civn.nhkz || ''
										if (idcardData.simh.civn.iqlo) {
											console.log('this.dropdowns.sex', this.dropdowns.sex);
											const genderresult = this.dropdowns.sex.find(item => item
												.text ==
												idcardData.simh.civn.iqlo);
											console.log(genderresult);
											this.gendercode = genderresult.value
										}
										if (idcardData.simh.civn.xqyf) {
											this.idnumber = idcardData.simh.civn.xqyf.replace(/\s+/g,
												'');
											console.log('this.idnumber', this.idnumber);
										}
										let shijianchuoData = idcardData.simh.civn
											.qcce; // "20 Dec. 1996"
										if (shijianchuoData != "" && shijianchuoData != " " &&
											shijianchuoData != null && shijianchuoData != undefined) {
											const timestamp = this.parseDateToTimestamp(
												shijianchuoData);
											console.log('处理好的timestamp', timestamp);
											console.log('后台返回的日期:', shijianchuoData);
											// this.birthValue = isNaN(timestamp) ? '' : new Date(
											// 		timestamp)
											// 	.toISOString().split('T')[0];
											if (!isNaN(timestamp)) {
												this.birthValue = new Date(timestamp).toISOString()
													.split('T')[0];
											}

											console.log('birthValue:哈哈哈哈', this.birthValue);
											uni.setStorageSync('setbirth', true)
										}
										this.addressValue = idcardData.simh.civn.gylr.trim() || ''
									})
								}
								// 刷新页面
								let params = {
									vjeu: '4'
								}
								api.getPhotoUrl(params).then(data => {
									console.log('--身份证照片回显res', data);
									this.$nextTick(() => {
										this.idcardsrc = ''; // 先清空
										console.log('更新页面', data.fumf);
										this.idcardsrc = data.fumf;
									});
									this.idacrdPasses = true
									if (uni.getStorageSync('facePhotoUpload')) {
										if (this.idacrdPasses && this.FacePasses) {
											api.ComparisonFaceIDcard().then(data => {
												console.log('认证对比分数！');
											})
										}
									}
									console.log('this.idcardsrc', this.idcardsrc);
								})
								setDot('SYSTEM_ID_PICTURE_SUCCESS')
							} else {
								uni.showToast({
									icon: 'none',
									title: idcardData.ytlt
								})
							}


						}
						uni.hideLoading()
					},
					fail: (res) => {
						this.idacrdPasses = false
						console.log('上传失败', res);
						uni.showToast({
							icon: 'none',
							title: this.$t('idcard.errormsg')
						})
						uni.hideLoading()
					}
				});
			},
			fn1() {
				this.handleClick = true;
				console.log('页面各种时长', this.fillTimes);
				const requiredFields = [
					'idcrdThaiName',
					'englishName',
					'otherThaiName',
					'gendercode',
					'idnumber',
					'addressValue',
				];

				// 确保所有必填字段都不为空
				const cansubmit = requiredFields.every(field => this[field] && this[field].trim() !== '');

				console.log('可以提交了吗', cansubmit,
					'身份证照片上传了吗', this.idacrdPasses,
					'人脸照片上传了吗', this.FacePasses,
					'日期选择了吗', this.formatTimestamp(this.birthValue),
					'当前日期', this.formatTimestamp(Number(new Date()))
				);

				// 确保生日不为空
				let notemptyBirth = true;
				if ((this.formatTimestamp(this.birthValue) === this.formatTimestamp(Number(new Date()))) && !this
					.showtoadybirth) {
					notemptyBirth = false;
				}
				console.log('烦死了', notemptyBirth, '而欸额0', this.showtoadybirth);

				// 确保所有条件都满足后执行操作
				if (cansubmit && this.idacrdPasses && notemptyBirth && this.FacePasses) {
					console.log('可以提交了');
					let params = {
						vjeu: '4',
						scyd: this.englishName,
						mcgw: this.idcrdThaiName,
						fspg: this.otherThaiName,
						iqlo: this.gendercode,
						tjhc: this.idnumber,
						gjoi: this.addressValue,
						vzbc: this.fomatterDateForUpdate(this.birthValue)
					}
					console.log('传参', params);
					api.uploadUserInfo(
						params
					).then(data => {
						setDot('CLICK_ID_INF_SUBMIT')
						console.log('id卡存储成功');
						this.endTiming('page')
						console.log('人脸识别页面停留时长', this.fillTimes.page);
						console.log('可以跳转页面了!!!!');
						setfengkongDot('DNICompleteDuration', this.fillTimes.idnumber)
						setfengkongDot('PaternalSurnameCompleteDuration', this.fillTimes.englishName)
						setfengkongDot('MaternalSurnameCompleteDuration', this.fillTimes.idcrdThaiName)
						setfengkongDot('nameCompleteDuration', this.fillTimes.otherThaiName)
						setfengkongDot('DateOfBirthCompleteDuration', this.fillTimes.birthValue)
						setfengkongDot('AdressCompleteDuration', this.fillTimes.addressValue)
						setfengkongDot('GenderCompleteDuration', this.fillTimes.gendercode)
						//停留总时长
						setfengkongDot('PersonalDetailsPageStopDurationALL', this.fillTimes.page)

						//填写总时长
						setfengkongDot('PersonalDetailsPageCompleteDurationALL',
							Number(this.fillTimes.idcardfrontupload || 0) +
							Number(this.fillTimes.faceupload || 0) +
							Number(this.fillTimes.englishName || 0) +
							Number(this.fillTimes.idcrdThaiName || 0) +
							Number(this.fillTimes.otherThaiName || 0) +
							Number(this.fillTimes.birthValue || 0) +
							Number(this.fillTimes.idnumber || 0) +
							Number(this.fillTimes.addressValue || 0)
						)

						// 页面跳转逻辑（取消注释即可生效）
						uni.navigateTo({
							url: '/pages/demo4/demo4',
							animationType: 'slide-in-right',
							animationDuration: 200
						});
						uni.removeStorageSync('setbirth')
						this.clearSelectStartFlags()
					})
				}
			},
			// 开始计时
			startTiming(field) {
				this.startTimes[field] = Date.now();
			},
			// 结束计时并计算时长
			endTiming(field) {
				console.log('计算结束时长', field);
				if (this.startTimes[field]) {
					const endTime = Date.now();
					this.fillTimes[field] = endTime - this.startTimes[field];
					this.startTimes[field] = null; // 重置
				}
			},
			clickeFun(field) {
				const key = `${field}Changebegin`;
				if (!uni.getStorageSync(key)) {
					this.startTiming(field);
					uni.setStorageSync(key, true)
				}
			},
			handleSelectChange(field) {
				const key = `${field}Changebegin`;
				if (uni.getStorageSync(key)) {
					this.endTiming(field);
				}
			},
			clearSelectStartFlags() {
				const keys = [
					'birthValueChangebegin',
					'gendercodeChangebegin'
				];
				keys.forEach(key => uni.removeStorageSync(key));
			},
			fomatterDateForUpdate(timestamp) {
				const date = new Date(timestamp);
				const day = String(date.getDate()).padStart(2, '0');
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要+1
				const year = date.getFullYear();
				return `${day}-${month}-${year}`;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.P-5 {
		width: 100%;
		background-image: url('/static/inputborder.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		padding: 6rpx 20rpx;
		box-sizing: border-box;
		height: 100rpx;
	}

	::v-deep .uni-input-input {
		font-size: 16px !important;
	}

	::v-deep .uni-input-placeholder {
		color: #999 !important;
		font-size: 16px !important;
	}

	.P-head {
		width: 100%;
		background-color: #1F2022;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		padding: 30rpx;
		box-sizing: border-box;
		margin-top: -110rpx;


		image {
			width: 100rpx;
			height: 100rpx;
		}
	}

	.P-1 {
		margin-top: 20px;

		image {
			width: 100%;
			height: 54rpx;
		}

		p {
			width: 100%;
			text-align: start;
			color: #BCA3F3;
			font-size: 18rpx;
		}
	}

	.flexrowspacebetween {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.flexrowstart {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.flexcenter {
		display: flex;
		justify-content: center;
		align-items: center;
		align-content: center;
	}

	.P-id {
		margin-top: 30rpx;

		image {
			width: 150rpx;
			height: 120rpx;
		}

		.facetipasimg {
			height: 150rpx;
		}
	}

	.P-idimg-box {
		width: 100%;
		margin-bottom: 10rpx;
		height: fit-content;
		// height: 180rpx;
		box-sizing: border-box;

		image {
			width: 300rpx;
			height: 180rpx;
		}

		.img {
			width: 300rpx;
			height: 250rpx;
		}
	}


	.P-2 {
		width: 100%;
		margin: 20rpx 0rpx;

		.P-2-title {
			height: 100rpx;
			background-image: url('../../static/tipsbg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 0rpx 20rpx;

			image {
				width: 50rpx;
				height: 50rpx;
				margin-right: 40rpx;
			}
		}

		.gradient-text {
			background: linear-gradient(to bottom, rgba(204, 154, 243, 1), #F9E4B7);
			-webkit-background-clip: text;
			-webkit-text-fill-color: transparent;
			font-weight: bold;
			font-size: 32rpx;
			/* 根据需要调节 */
		}

		p {
			width: 86%;
			height: 90rpx;
			background-color: #FFF584;
			text-align: center;
			color: #000;
			line-height: 90rpx;
			border-radius: 20rpx;
			font-size: 40rpx;
			box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.2);
			transition: all 0.2s;
			// animation: pulsebtn 1.2s ease-in-out infinite;

		}

		p:active {
			transform: scale(0.96);
			box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.2);
		}

		@keyframes pulsebtn {
			0% {
				transform: scale(1);
			}

			50% {
				transform: scale(1.08);
			}

			100% {
				transform: scale(1);
			}
		}

	}

	.P-6 {
		background-color: #393A3D;
		padding: 20rpx 30rpx;
		border-radius: 20rpx;
		font-size: 28rpx;
		margin: 40rpx 0rpx 30rpx 0;

		.content-1 {
			box-sizing: border-box;
			color: #FF9E6F;

			image {
				width: 43rpx;
				height: 43rpx;
			}

			p {
				margin-left: 20rpx;
				width: 86%;
			}

		}
	}

	.flexcentercloumn {
		display: flex;
		justify-content: center;
		align-items: center;
		align-content: center;
		flex-direction: column;
	}

	.datapickerxiala {
		margin-top: 10px;
		padding: 30rpx 20rpx;
		height: 100%;
		box-sizing: border-box;
		background-image: url('/static/inputborder.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: relative;
	}

	.tishi {
		width: 295px;
		height: 57px;
		margin-top: 35px;
	}
</style>